package com.wgchao.authodemo.application.mapstruct.mapper.dtod.expand;

import com.wgchao.authodemo.domian.entity.base.AgencyDO;
import com.wgchao.authodemo.application.mapstruct.DTOMapper;
import com.wgchao.authodemo.application.mapstruct.dto.AgencyDTO;
import com.wgchao.authodemo.application.mapstruct.mapper.dtod.AgencyMapper;
import com.wgchao.authodemo.domian.event.base.AgencyEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @ClassName: AgencyDTOExpand
 * @author: wgchao
 * @createTime: 2019/12/10 4:21 PM
 * @Description: TODO
 */
@Component
public class AgencyMapperExpand implements DTOMapper<AgencyDO,AgencyDTO> {
    @Autowired
    private AgencyMapper agencyMapper;
    @Autowired
    private AgencyEvent agencyEvent;

    @Override
    public AgencyDO toEntity(AgencyDTO agencyDTO) {
        return agencyMapper.toEntity(agencyDTO);
    }

    @Override
    public AgencyDTO toDTO(AgencyDO agencyDO) {
        return agencyMapper.toDTO(agencyDO);
    }

    @Override
    public List<AgencyDO> toEntity(List<AgencyDTO> agencyDTOS) {
        return agencyMapper.toEntity(agencyDTOS);
    }

    @Override
    public List<AgencyDTO> toDTO(List<AgencyDO> agencyDOS) {
        return agencyMapper.toDTO(agencyDOS);
    }

    public AgencyDTO setParAgency(AgencyDTO agencyDTO){
        if(!StringUtils.isEmpty(agencyDTO.getParAgencyCode())){
            AgencyDO agencyDO = agencyEvent.search(agencyDTO.getParAgencyCode());
            if(agencyDO != null){
                agencyDTO.setParAgency(toDTO(agencyDO));
            }
        }
        return agencyDTO;
    }
}
